require "import"
import "android.content.Context"
import "android.view.KeyEvent"
import "android.media.AudioManager"
import "java.util.Locale"
import "com.androlua.*"

local audioManager = service.getSystemService(Context.AUDIO_SERVICE)

local eventDown = KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)
local eventUp = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)

audioManager.dispatchMediaKeyEvent(eventDown)
audioManager.dispatchMediaKeyEvent(eventUp)

local lang = Locale.getDefault().getLanguage()

if lang == "ar" then
    this.speak("تبديل الوسائط")
elseif lang == "fr" then
    this.speak("Lecture ou pause")
else
    this.speak("Toggle media")
end

return true
